// pages/projects/projects.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
     imgPath:"/images",
     dataList:[],
     channel:'',
     is_share:'',
     flag:false,
     pop_share:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
   // console.log('optionsoptions',options);
    if(options.channel&&options.is_share){
      // const util = require("../../utils/util")
      // util.setTabbarActive('plan');
      wx.redirectTo({
       // url: '/pages/plan/joinPlan?channel='+options.channel+'&is_share='+options.is_share
        url: '/pages/index/index?query=fengxiang&channel='+options.channel+'&is_share='+options.is_share
      })
    }
   // this.getShareData();
    wx.setNavigationBarTitle({
          title: '邀请好友',
        })
    const util=require("../../utils/util")
    const api = require("../../api/api")
    const that = this;
    api.user.sharegifts({
      success(res) {
        if(res.data.code == 0){
          //刷新数据
          that.setData({
            dataList:res.data.data
          });   
        }
      }
    })
       this.setData({
        imgPath:util.getImgPath()
      })
  },
  goshare(){
         this.setData({
          pop_share:true
         });
  },
  close_share(){
    this.setData({
      pop_share:false
     });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    const util = require("../../utils/util")
    const api = require("../../api/api");
    let sceneId = util.getuserEnterAppletMode();   // 场景码
    let that = this;
    api.user.getUserChannel({
      success(res) {
        let channel = res.data.data.channel;
        let is_share = res.data.data.is_share;
        that.setData({
          channel,
          is_share
        });
      }
    })
   
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
  // return this.getShareData(res.target.dataset.type);
    let that = this;
    let home = wx.getStorageSync('home');
    return {
      title:'你邀我送，助力成长',
      imageUrl:'http://qnstatic.lianhequnmei.com/images/huodong/huodong_02.png',
    //  path:'/pages/plan/joinPlan?channel='+this.data.channel+'&is_share='+this.data.is_share,
      path:'/pages/index/index?query=fengxiang&channel='+this.data.channel+'&is_share='+this.data.is_share,
      success: function (res) { 
          wx.showShareMenu({
            withShareTicket: true,
            success: function (res) {
              console.log(res)
            },
            fail: function (res) {
              console.log(res)
            }
          })
      },
      fail: function (res) {
        console.log("转发失败:");
      }
    };
  },
  onShareTimeline: function () {
     //  return this.getShareData("timeline");
     let title = "你邀我送，助力成长";
     let imageUrl = "http://qnstatic.lianhequnmei.com/images/huodong/huodong_02.png";
     let path = "channel=" + this.data.channel + "&is_share=" + this.data.is_share; // 暂不支持自定义路径，只能带参数
     return {
      title,
      imageUrl,
      query: path,
     }
    },
    tips(){
     wx.showToast({
          title: '请点击右上角分享到朋友圈',
          icon:'none',
        })
    },
    getShareData(type) {
      let that = this
      let home = wx.getStorageSync('home');
      let title = "你邀我送，助力成长";
      let imageUrl = "http://qnstatic.lianhequnmei.com/images/huodong/huodong_02.png";
      let path = '/pages/plan/joinPlan?channel='+this.data.channel+'&is_share='+this.data.is_share;
      if (type == "timeline") {
                return {
                          title,
                          imageUrl,
                          query: path,
                };
      }
      return {
        title,
        imageUrl,
        path,
        success: function (res) { 
            wx.showShareMenu({
              withShareTicket: true,
              success: function (res) {
                console.log(res)
              },
              fail: function (res) {
                console.log(res)
              }
            })
        },
        fail: function (res) {
          console.log("转发失败:");
        }
      };
},




})